package com.thread.upload;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;

public class FileUtil {

	/**
	 * 写入一个空文件
	 * @param fileName 文件名
	 * @param str 写入的内容
	 * @return
	 */
	public static boolean writeFile(String fileName, String str) {
		OutputStream os = null;
		PrintWriter pw = null;
		try {
			File file = new File(fileName);
			os = new FileOutputStream(file);
			pw = new PrintWriter(os);
			pw.write(str);
			pw.flush();
			return true;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} finally {
			try {
				if (os != null)
					os.close();
				if (pw != null)
					pw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
		return false;

	}

	/**
	 * 删除文件
	 * @param fileName 文件名
	 * @return
	 */
	public static boolean deleteFile(String fileName) {
		File file = new File(fileName);
		if (file.exists()) {
			boolean delete = file.delete();
			return delete;
		}
		return false;

	}
}
